$(document).ready(function() {

	var table = $('#table').DataTable({
		"order" : [ [ 6, "desc" ] ],// desc默认排序
		"paging" : true,
		"dom" : '<"top">rt<"bottom"ip><"clear">',
		"type" : "post",
		"ajax" : {
			"url" : basePath + "/log/getLogList.do",
			"data" : function(d) {
				d.operationType=$('#op-type option:selected').val(),
				d.businessType=$('#business-type option:selected').val(),
				d.status=$('#op-status option:selected').val(),
				d.userName=$('#user-name').val()
			}
		},
		"serverSide" : "true",
		"processing" : "true",
		select: {
            style: 'multi'
        },
		"columns" : [ 
			  {data : "regName"}, 
			  {data : "operationType"}, 
			  {data : "businessType"}, 
			  {data : "businessId"}, 
			  {data : "remark"},
			  {data : "status"},
			  {data : "createdAt"},
			  {data : "createdAtStr"}

		],
		"columnDefs" : [
		      {
					"targets" : 6,
					"data" : null,
					"render" : function(data,type, row) {
						return row.createdAtStr;
					}
		      },
		      {
					"targets" : 1,
					"data" : null,
					"render" : function(data,type, row) {
						return renderOperationType(data);
					}
		      },
		      {
					"targets" : 2,
					"data" : null,
					"render" : function(data,type, row) {
						return renderBusinessType(data);
					}
		      },
		      {
					"targets" : 5,
					"data" : null,
					"render" : function(data,type, row) {
						return renderStatus(data);
					}
		      }, {
					"targets" : 7,
					visible : false
				}
		]
	// end of columnDefs

	}).on('preXhr.dt',function(e, settings, data) {

		showLoading("loadingLogs");

	}).on('xhr.dt',function(e, settings, data) {

		hideLoading("loadingLogs");

	}).on('processing.dt',function(e, settings, processing) {

	}).on('error.dt',function(){
    	//window.location.reload();
    });// end of dataTable

	$('#res-table tbody').on('click','tr',function() {
		
		$('#res-table tr.selected').removeClass('selected');
		
		$(this).addClass('selected');
		
	});	
	
	$('#filter-log').on('click',function(){
		table.ajax.reload();
	})
	

})

//render操作类型
function renderOperationType(data)
{
	var temp='<input type="hidden" value="{0}"><label class="label {1}">{2}</label>';

	if (data == 'insert') {
		
		return temp.format(data,"label-success","增"); 
	}

	if (data == 'update') {
		
		return temp.format(data,"label-info","改");
		
	}
	
	if (data == 'delete') {
		
		return temp.format(data,"label-warning","删");
		
	}
	
	return temp.format(data,"label-danger","未知");
}
//render业务类型
function renderBusinessType(data)
{
	var temp='<input type="hidden" value="{0}"><label class="label {1}">{2}</label>';

	if (data == 'demand') {
		
		return temp.format(data,"label-success","需求"); 
	}
	if (data == 'complaint') {
		
		return temp.format(data,"label-success","投诉"); 
	}
	if (data == 'quotation') {
		
		return temp.format(data,"label-success","报价单"); 
	}
	if (data == 'FieldRecord') {
		
		return temp.format(data,"label-success","实地记录"); 
	}
	if (data == 'FactoryInspection') {
		
		return temp.format(data,"label-success","验厂报告"); 
	}
	
	if (data == 'contract') {
		
		return temp.format(data,"label-success","合同"); 
	}
	
	return temp.format(data,"label-danger","未知");
}


function renderStatus(data)
{
	var temp='<input type="hidden" value="{0}"><label class="label {1}">{2}</label>';

	if (data == '1') {
		
		return temp.format(data,"label-success","成功"); 
	}
	
	if (data == '0') {
		
		return temp.format(data,"label-warning","失败"); 
	}
	
	return temp.format(data,"label-danger","未知");
}
